﻿var job;
$(function () {
    bindStatus();

    $("#areaId").ligerComboBox({
        width: 100,
        cancelable: false,
        url: "/Personnel/NurseLevelReview/GetDepartmentList?ram" + Math.random(),
        parms: { isAll: 1 },
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnAreaId',
        value: -1,
        onSuccess: function (data) { }
    });

    $('#btnSearch').click(function () {
        search();
    });

    search();
});

function bindStatus() {
    var JsonObj = [];

    $.ajax({
        url: "/Personnel/NurseLevelReview/GetReviewProcess?ram" + Math.random(),
        type: "post",
        async: false,
        success: function (r) {
            job = $.parseJSON(r);
            JsonObj.push({ text: "全部", value: -1 });
            if (job.IncludeStatus == "" || job.IncludeStatus == null) return;
            var includeStatus = job.IncludeStatus.split('|');
            var statusAlias = job.StatusAlias.split('|');
            for (var ii = 0; ii < includeStatus.length; ii++) {
                JsonObj.push({ text: statusAlias[ii], value: includeStatus[ii] });
            }
        }
    });

    $("#status").ligerComboBox({
        width: 120,
        cancelable: false,
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnStatus',
        data: JsonObj,
        value: -1
    });
}

//加载列表
function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Personnel/NurseLevelReview/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
        { display: '工号', name: 'UserId' },
        { display: '姓名', name: 'Name' },
        { display: '现能级', name: 'NowLevel', render: function (row) { return row.NowLevel == "0" ? "" : row.NowLevel } },
        { display: '申请能级', name: 'ApplyLevel' },
        { display: '提交时间', name: 'CommitTime' },
        { display: '病区', name: 'DepartmentName' },
        {
            display: '审核状态', name: '', render: function (row) {
                if (job.IncludeStatus == null) return;
                var html = '';
                var includeStatus = job.IncludeStatus.split('|');
                var statusAlias = job.StatusAlias.split('|');
                for (var i = 0; i < includeStatus.length; i++) {
                    if (includeStatus[i] == row.Status) {
                        html = statusAlias[i];
                        break;
                    }
                }
                return html;
            }
        },
        {
            display: '操作', name: '', minWidth: 100, render: function (row) {
                if (job.Status == null) return;
                var html = '<div style="heigth:100%;width:100px;text-align: left;margin:0px auto;">';
                for (var i = 0; i < job.Status.length; i++) {
                    var statusItem = job.Status[i];
                    if (statusItem.Value == row.Status) {
                        var viewBtns = statusItem.ViewBtns;
                        for (var ii = 0; ii < viewBtns.length; ii++) {
                            var viewBtn = viewBtns[ii];
                            var detailsViewBtns = JSON.stringify(viewBtn.DetailsViewBtns).replace(/([^\\])"/g, "$1\\'");
                            html += '<a href="javascript:void(0);"  class="a-edit" onclick="' + viewBtn.Function + '(' + eval(viewBtn.Parameter) + ',\'' + detailsViewBtns + '\',' + row.Status + ')">' + viewBtn.BtnName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;';
                        }
                        break;
                    }
                }
                html += "</div>";
                return html;
            }
        }]
    });
    GridNoData($("#maingrid"));
}

//搜索
function search(pageNumber) {
    var queryData = {
        status: $("#hdnStatus").val(),
        name: $("#txtName").val(),
        areaId: $("#hdnAreaId").val()
    }
    initTable(queryData, pageNumber);
}

//审核/编辑/查看
function edit(id, obj, status) {
    window.location.href = "/Personnel/EditNurseLevel/Index?id=" + id + "&pageType=1&detailsViewBtns=" + obj + "&status=" + status;
}